<html>
<title>AJAX server clock</title>
<head>

<script type='text/javascript' src='javascript/sarissa/sarissa.js'></script>
<script type="text/javascript" src="javascript/sarissa/sarissa_ieemu_xpath.js"></script>
<script type='text/javascript'>
var http_request;
/*
 * Create an http request object and send a date request to server
 */ 
function setupAJAX() {
//   window.status +=".";
   http_request= new XMLHttpRequest();
   if (!http_request) 
	   alert("Can't create XMLHttpRequest object");
    http_request.onreadystatechange= handle_server_response;
    http_request.open('GET', 'time.jsp', true);
    http_request.send(null);
}//setupAJAX

function handle_server_response() {
     if (http_request.readyState == 4){
          window.status +="+";
          date_obj = document.getElementById('date_elt');
          if (!date_obj)
             alert("Can't find date display object");
          date_obj.firstChild.data= extractDate(http_request.responseText);
          window.setTimeout("setupAJAX()",1000);
     }//if '4' response
  }//handle_server_response
  
 /*
  * Returns the text content of the first "date_response" element in xmlText
  */
function extractDate(xmlText) {

    xmlDoc = Sarissa.getDomDocument();
    xmlDoc = (new DOMParser()).parseFromString(xmlText,"text/xml");
   // alert(Sarissa.serialize(xmlDoc));
    dates = xmlDoc.selectNodes("/date_response");
    //alert("Node type: "+dates.item(0).nodeType+" child type: "+dates.item(0).firstChild.nodeType);
    
    return dates.item(0).firstChild.data;
}//extractDate()
    
  

</script>
<style type='text/css'>
  BODY {font-family:Arial}
  SPAN {color:green}
  H1   {color:red}
</style>
</head>
<body onload='window.status="Initializing";setupAJAX()'>
<h1>XMLHttp example</h1>
<p>Probe the server at 1-second intervals for the time.
If your page gets stuck on the initial date, try disabling caching.</p>
<p>Current date, from server: <span id='date_elt'>unknown</span>.</p>
</body>
</html>
